<?
if (!defined('MODULE_FILE')){
die ("cant access file directly!");
}

$mid 	= ( ( true == isset( $_GET['mid'] ) && true == valStr( $_GET['mid'] ) ) ? $_GET['mid'] : NULL );
$smid 	= ( ( true == isset( $_GET['smid'] ) && true == valStr( $_GET['smid'] ) ) ? $_GET['smid'] : NULL );

autoLoader();

$objBasePatient 	= new BasePatients();
$objPatients 		= new Patients();
$objPatientTypes 	= new PatientCatagories();

?>
<html>
<head>
<?php require_once 'commonJS.php'; ?>
</head>
<body>
<br>
<div class="col-lg-8">
	<div class="panel panel-primary">
		<div class="panel-heading"><i class="fa fa-bell fa-fw"></i> Patients</div>
		<div class="panel-body">
			<form METHOD="POST" action="modules.php?file=insert_patient&type=insert&mid=<? echo $mid; ?>&smid=<? echo $smid; ?>" id="formSubmit" name="formSubmit" >
			
			<?php
				$intPatientId 		= NULL;
				$strFirstName 		= NULL;
				$strMiddleName 		= NULL;
				$strLastName 		= NULL;
				$strMotherName 		= NULL;
				$intAge 			= NULL;
				$strGender 			= NULL;
				$strMaritalStatus 	= NULL;
				$strOccupaction 	= NULL;
				$strHomeNumber 		= NULL;
				$strOfficeNumber 	= NULL;
				$strMobileNumber 	= NULL;
				$strEmailAddress 	= NULL;
				$intPatientTypeId 	= NULL;
				
				$intReferancePatientId 		= NULL;
				
				if( true == isset( $_GET['patient_id'] ) && true == valStr( $_GET['patient_id'] ) ) {
					$intPatientId = $_GET['patient_id'];
					
					$objBasePatient = $objPatients->fetchPatientsById( $intPatientId );
					
					if( true == valObj( $objBasePatient, 'BasePatients' ) ) {
						$intPatientId 		= $objBasePatient->getId();
						$strFirstName 		= $objBasePatient->getFirstName();
						$strMiddleName 		= $objBasePatient->getMiddleName();
						$strLastName 		= $objBasePatient->getLastName();
						$strMotherName 		= $objBasePatient->getMotherName();
						$intAge 			= $objBasePatient->getAge();
						$strGender 			= $objBasePatient->getGender();
						$strMaritalStatus 	= $objBasePatient->getMaritalStatus();
						$strOccupaction 	= $objBasePatient->getOccupaction();
						$strHomeNumber 		= $objBasePatient->getHomeNumber();
						$strOfficeNumber 	= $objBasePatient->getOfficeNumber();
						$strMobileNumber 	= $objBasePatient->getMobileNumber();
						$strEmailAddress 	= $objBasePatient->getEmailAddress();
						$intPatientTypeId 	= $objBasePatient->getPatientTypeId();
						
						$intReferancePatientId = $objBasePatient->getPatientId();
					}
				} else if( true == valObj( $objBasePatient, 'BasePatients' ) ) {
					$intPatientId = $objBasePatient->fetchNextId();
				}
			?>
				<table width="80%" cellspacing="0" cellpadding="3">
		
					<tr><td height="10" colspan="2"></td></tr>
					<tr><td colspan="2" height="10px"></td></tr>
					
					<tr valign="top">
						<td  width="220">Patient ID</td>
						<td><input id="patient_id" Name="patient_id" type="text" class="" style="width:100px;" readonly="readonly" value="<?php echo $intPatientId; ?>"></td>
					</tr>
					
					<tr><td colspan="2" height="10px"></td></tr>
					
					<tr valign="top">
						<td width="220">Patient Type ID</td>
						<td>
							<select class="validate[required]" name="patient_type_id" id="patient_type_id" style="width:202px;">
								<option value=''> ------ Select ------ </option>
							<?php
								$arrobjPatientTypes = $objPatientTypes->fetchAllPatientCatagories();
								
								if( true == valStr( $arrobjPatientTypes ) ) {
									foreach( $arrobjPatientTypes as $objPatientType ) {
										echo '<option' . ( ( $intPatientTypeId == $objPatientType->getId() ) ? ' selected' : '' ) . ' value=' . $objPatientType->getId() . '>' . $objPatientType->getName() . '</option>';
									}
								}
							?>
							</select>
						</td>
					</tr>
					
					<tr><td colspan="2" height="10px"></td></tr>
					
					<tr valign="top">
						<td  width="220">Referance Patient ID</td>
						<td><input id="referance_patient_id" Name="referance_patient_id" type="text" class="" style="width:202px;" value="<?php echo $intReferancePatientId; ?>"></td>
					</tr>
					
					<tr><td colspan="2" height="10px"></td></tr>
					
					<tr valign="top">
						<td  width="220">First Name</td>
						<td><input id="first_name" Name="first_name" type="text" class="validate[required]" style="width:202px;" value="<?php echo $strFirstName; ?>"></td>
					</tr>
					<tr>
						<td colspan="2" height="10px"></td>
					</tr>
					 <tr valign="top">
						<td  width="220">Middle Name</td>
						<td><input id="middle_name" Name="middle_name" type="text" class="" style="width:202px;" value="<?php echo $strMiddleName; ?>"></td>
					</tr>
					<tr>
						<td colspan="2" height="10px"></td>
					</tr>
					<tr valign="top">
						<td  width="220">Last Name</td>
						<td><input id="last_name" Name="last_name" type="text" class="validate[required]" style="width:202px;" value="<?php echo $strLastName; ?>"></td>
					</tr>
					<tr>
						<td colspan="2" height="10px"></td>
					</tr>
					<tr valign="top">
						<td  width="220">Mother Name</td>
						<td><input id="mother_name" Name="mother_name" type="text" class="" style="width:202px;" value="<?php echo $strMotherName; ?>"></td>
					</tr>
					<tr>
					<tr>
						<td colspan="2" height="10px"></td>
					</tr>
					<tr valign="top">
						<td  width="220">Age</td>
						<td><input id="age" Name="age" type="text" class="validate[required]" style="width:202px;" value="<?php echo $intAge; ?>"></td>
					</tr>
					<tr>
						<td colspan="2" height="10px"></td>
					</tr>
					<tr valign="top">
						<td  width="220">Gender</td>
						<td>
							<select class="validate[required]" name="gender" id="gender" style="width:202px;">
								<option value=''>-Select-</option>
								<option value='1' <?php echo ( ( 1 == $strGender ) ? 'selected' : '' ); ?>>Male</option>
								<option value='2' <?php echo ( ( 2 == $strGender ) ? 'selected' : '' ); ?>>Female</option>
								<option value='3' <?php echo ( ( 3 == $strGender ) ? 'selected' : '' ); ?>>Other</option>
							</select>
						</td>
					</tr>
					<tr>
						<td colspan="2" height="10px"></td>
					</tr>
					<tr valign="top">
						<td  width="220">Marital Status</td>
						<td><input id="marital_status" Name="marital_status" type="text" class="validate[required]" style="width:202px;" value="<?php echo $strMaritalStatus; ?>"></td>
					</tr>
					<tr>
						<td colspan="2" height="10px"></td>
					</tr>
					<tr valign="top">
						<td  width="220">Occupation</td>
						<td><input id="occupaction" Name="occupaction" type="text" class="validate[required]" style="width:202px;" value="<?php echo $strOccupaction; ?>"></td>
					</tr>
					<tr>
						<td colspan="2" height="10px"></td>
					</tr>
					<tr valign="top">
						<td  width="220">Home Number</td>
						<td><input id="home_number" Name="home_number" type="text" style="width:202px;" value="<?php echo $strHomeNumber; ?>"></td>
					</tr>
					<tr>
						<td colspan="2" height="10px"></td>
					</tr>
					<tr valign="top">
					<td  width="220">Office Number</td>
						<td><input id="office_number" Name="office_number" type="text" style="width:202px;" value="<?php echo $strOfficeNumber; ?>"></td>
					</tr>
					<tr>
						<td colspan="2" height="10px"></td>
					</tr>
					<tr valign="top">
						<td  width="220">Mobile Number</td>
						<td><input id="mobile_number" Name="mobile_number" type="text" class="" style="width:202px;" value="<?php echo $strMobileNumber; ?>"></td>
					</tr>
					<tr>
						<td colspan="2" height="10px"></td>
					</tr>
					<tr valign="top">
						<td  width="220">E-mail Address</td>
						<td><input id="email_address" Name="email_address" type="text" class="" style="width:202px;" value="<?php echo $strEmailAddress; ?>"></td>
					</tr>
					<tr>
						<td colspan="2" height="10px"></td>
					</tr>
					
					<tr>
						<td colspan="2" height="10px"></td>
					</tr>
					<tr valign="top">
						<td class="mandatory" width="220">&nbsp;</td>
						<td>
							<?php
								if( true == isset( $_GET['patient_id'] ) && true == valStr( $_GET['patient_id'] ) ) {
									echo "<input type=hidden name=operation value=update>";
									echo "<input type=submit value=UPDATE id=Submit name=Submit>";
								} else {
									echo "<input type=hidden name=operation value=insert>";
									echo "<input type=submit value=SUBMIT id=Submit name=Submit>";
								}
							?>
							<a href="modules.php?file=view_patients&type=view&mid=<? echo $mid; ?>&smid=<? echo $smid; ?>"><input type="button" name="calcle" value="Cancel" /></a>
						</td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</div>
</body>
</html>